package com.itheima.train.manager.order.configuration;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;

/**
 * @program: itheima-train-manager-parent
 * @description:
 * @author: zhanghz001
 * @create: 2021-07-06 14:12
 **/
// @Configuration
public class ZhzRabbitmqConfiguration {
    
    //声明队列
    @Bean("syn_stock_es_queue")
    public Queue synStockEsQueue() {
        return QueueBuilder.durable("syn_stock_es_queue").build();
    }
    
    @Bean("syn_gen_order_queue")
    public Queue synGenOrderQueue() {
        return QueueBuilder.durable("syn_gen_order_queue").build();
    }
    
    //声明交换机
    @Bean("train_manager_ex")
    public Exchange trainManagerEx() {
        return ExchangeBuilder.directExchange("train_manager_ex").build();
    }
    
    //绑定交换机和队列
    @Bean
    public Binding trainManagerExBindingStockEsQueue(@Qualifier("syn_stock_es_queue") Queue queue,
                                                     @Qualifier("train_manager_ex") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("syn_stock").noargs();
    }
    
    //绑定交换机
    @Bean
    public Binding synGenOrderQueueBindingExchange(
            @Qualifier("syn_gen_order_queue") Queue queue,
            @Qualifier("train_manager_ex") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("gen_order").noargs();
    }
}
